﻿using System.Xml.Linq;
using AzukiMap.Renderer;
using AzukiMap.Tools;

namespace AzukiMap.Layer
{
    public class VectorLayerTheme 
    {
        int _id;
        string _expression;
        string _themeName;
        IVectorStyle _style;
        XmlCommon _xmlCommon;

        public int Themeid
        {
            get { return _id; }
            set { _id = value; }
        }

        public string Expression
        {
            get { return _expression; }
            set { _expression = value; }
        }

        public IVectorStyle Style
        {
            get { return _style; }
            set { _style = value; }
        }

        public string ThemeName
        {
            get { return _themeName; }
            set { _themeName = value; }
        }
        
        public VectorLayerTheme()
        {
        }

        public VectorLayerTheme(string expr, IVectorStyle st)
        {
            _expression = expr;
            _style = st;
            _id = Serial.GetSerialNumber();
            _themeName = "theme name";
        }

        public XElement ToXml()
        {
            XElement themeXml = new XElement("VectorLayerTheme",
                new XElement("ThemeName", _themeName),
                new XElement("ThemeId", _id),
                new XElement("Expression", _expression),
                //new XElement("Style", _style.ToXml())
                _style.ToXml("Style")
                );
            return themeXml;
        }

        public void Parse(XElement themeXml)
        {
            _xmlCommon = new XmlCommon();
            _id = _xmlCommon.GetIntElement(themeXml, "ThemeId");
            _expression = _xmlCommon.GetStringElement(themeXml, "Expression");
            _themeName = _xmlCommon.GetStringElement(themeXml, "ThemeName");
            _style = new VectorStyle();
            _style.Parse(themeXml.Element("Style"));
            /*
            base.Parse(mapSourceXml);
            XElement vectorSourceXml = mapSourceXml.Element("vectorSourceXml");
            _vectorType = (VectorSourceTypes)Enum.Parse(typeof(VectorSourceTypes), 
                vectorSourceXml.Element("VectorType").ToString(), true);
             */
            
        }
    }
}
